using System;
using System.Collections.Generic;
using System.Text;
using OpenTK.Math;

namespace Dogfight2008.Common
{
  public static class Calc
  {
    public const float Epsilon = 0.001f; // Unit meters; millimeter precision OK

    public static bool AlmostEqual(float a, float b)
    {
      return Math.Abs(a - b) < Epsilon;
    }

    public static bool AlmostEqual(Vector3 v1, Vector3 v2)
    {
      return AlmostEqual(v1.X, v2.X) && AlmostEqual(v1.Y, v2.Y) && AlmostEqual(v1.Z, v2.Z);
    }

    public static bool AlmostZero(float a)
    {
      return AlmostEqual(a, 0);
    }

    public static bool Equal(Vector3 v1, Vector3 v2)
    {
      return v1.X == v2.X && v1.Y == v2.Y && v1.Z == v2.Z;
    }

    public static float DegreesToRadians(float degrees)
    {
      return 0.0174532925f * degrees;
    }

    public static float RadiansToDegrees(float radians)
    {
      return radians / 0.0174532925f;
    }

    public static Vector2 v(double x, double y)
    {
      return new Vector2((float)x, (float)y);
    }

    public static Vector3 v(double x, double y, double z)
    {
      return new Vector3((float)x, (float)y, (float)z);
    }

    public static Vector2 Polar(double angle, double distance)
    {
      return v(Math.Cos(angle) * distance, Math.Sin(angle) * distance);
    }
  }
}
